﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AIOptimization.Algorithms;
using AIOptimization.Algorithms.Repositories;

namespace AIOptimization
{
    public class PSOTest : ParticleSwarmOptimization
    {
        public PSOTest()
        {
            NewIterationResult += new NewIterationResultEvent(PSOTest_NewIterationResult);
            SetParameter(10, 2, -100, 100, 1000, 0.729, 1.49445, 1.49445);
            List<AIOptimization.Algorithms.Repositories.Particle> results = Execute();

            foreach (var result in results)
            {
                Console.WriteLine(result.ToString());
            }
        }

        void PSOTest_NewIterationResult(object o, ParticleSwarmOptimization.PSOIterationEventArgs e)
        {
            Console.WriteLine(e.IterationNumber);
            foreach (var result in e.Swarm)
            {
                Console.WriteLine(result.ToString());
            }
            Console.ReadLine();
        }

        public override double ObjectiveFunction(double[] x)
        {
            return 3.0 + Math.Pow(x[0], 2) + Math.Pow(x[1], 2);
        }
    }
}
